<?php
/**
 * Manager for Db_Object events
 * @author Kirill A Egorov kirill.a.egorov@gmail.com 
 * @copyright Copyright (C) 2012  Kirill A Egorov, 
 * DVelum project http://code.google.com/p/dvelum/ , http://dvelum.net
 * @license General Public License version 3
 */
class Eventmanager extends Db_Object_Event_Manager
{
	static protected $_instance = null;
	
	protected function __construct(){}
	protected function __clone(){}
	/**
	 * @return Eventmanager
	 */
	static public function getInstance()
	{
		if(is_null(self::$_instance))
			self::$_instance = new self;
		return self::$_instance;	
	}
	/**
	 * (non-PHPdoc)
	 * @see Db_Object_Event_Manager::fireEvent()
	 */
	public function fireEvent($code, Db_Object $object)
	{
		$objectName = ucfirst($object->getName());
		$triggerClass = 'Trigger_' . $objectName;
		if(class_exists($triggerClass) && method_exists($triggerClass, $code)){
			call_user_func_array(array($triggerClass , $code), $object);
		}
	}
}